import axios from "axios";

const baseURL = process.env.VUE_APP_BASE_API;

console.log('baseURL', baseURL);
const apiClient = axios.create({
    baseURL: baseURL, // Replace with your API base URL
    headers: {
        "Content-Type": "application/json",
        // "token": localStorage.getItem('token') || ''
    },
});

// Add a request interceptor
apiClient.interceptors.request.use(
    (config) => {
        // You can modify the request config here (e.g., add auth tokens)
        return config;
    },
    (error) => {
        return Promise.reject(error);
    }
);

// Add a response interceptor
apiClient.interceptors.response.use(
    (response) => {
        // You can process the response data here
        return response && response.data || null;
    },
    (error) => {
        // Handle errors globally
        return Promise.reject(error);
    }
);

// 设置axios token
export const setToken = (token) => {
    apiClient.defaults.headers['token'] = token;
};

export default apiClient;